package com.yamaikeji.plan.controller;

import com.yamaikeji.common.annotation.Log;
import com.yamaikeji.common.core.controller.BaseController;
import com.yamaikeji.common.core.domain.AjaxResult;
import com.yamaikeji.common.enums.BusinessType;
import com.yamaikeji.system.domain.tts.Activation;
import com.yamaikeji.system.service.tts.IActivationService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author 桑伟杰
 * @date 2025-04-08
 * @description 激活码Controller
 */
@RestController
@RequestMapping("/api/tts/activation")
public class ActivationController extends BaseController {

    @Autowired
    private IActivationService activationService;

    /**
     * 激活软件
     */
    @Log(title = "激活软件", businessType = BusinessType.INSERT)
    @PostMapping("/activateCode")
    public AjaxResult activateCode(@RequestBody Activation activation) {
        if (StringUtils.isBlank(activation.getCode())) {
            return AjaxResult.error("激活码不能为空");
        }
        activation = activationService.selectActivation(activation);
        if (activation == null) {
            return AjaxResult.error("激活码不存在");
        }
        activation.setExpireTime(new Date());
        return AjaxResult.success(activation);
    }
}
